package com.zdgk.core.web.controller.slave;

import com.zdgk.core.control.forward.modbus.ModbusSlaveConfig;
import com.zdgk.core.control.forward.modbus.SlaveCache;
import com.zdgk.core.web.common.CommonResult;
import com.zdgk.core.web.controller.slave.entity.SlaveStatusEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class SlaveController {

    @Resource
    private ModbusSlaveConfig modbusSlaveConfig;

    /**
     * modbus从站状态
     * @return
     */
    @GetMapping("/slave/status")
    public CommonResult<?> iecStatus(){
        SlaveStatusEntity slaveStatusEntity = new SlaveStatusEntity();
        slaveStatusEntity.setIsConnected(modbusSlaveConfig.isConnected());
        return CommonResult.data(slaveStatusEntity);
    }

    @GetMapping("/slave/data")
    public CommonResult<?> data(){
        return CommonResult.data(SlaveCache.slaveCacheData);
    }

}
